package day4;



import java.util.Scanner;

public class Main {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n1 = in.nextInt();
        int n2 = in.nextInt();
        int n3 = in.nextInt();
        int n4 = in.nextInt();
        int A = (n1 + n3) / 2;
        int B1 = (n2 + n4) / 2;
        int B2 = (n3 - n1) / 2;
        int C = (n4 - n2) / 2;
        if (B1 == B2 && A >= 0 && B1 >= 0 && C >= 0 && (A - B1) == n1 &&
                (B1 - C) == n2 && (A + B1) == n3 && (B1 + C) == n4) {
            System.out.println(A + " " + B1 + " " + C);
            return;
        } else {
            System.out.print("No");
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()) {
            int m = in.nextInt();
            int n = in.nextInt();
            StringBuilder ret = new StringBuilder();
            String table = "0123456789ABCDEF";
            boolean flg = false;
            if(m < 0) {
                m = -m;
                flg = true;
            }
            if(m == 0) {
                ret.append('0');
            }
            while( m != 0) {
                ret.append(table.charAt( m % n));
                m /= n;
            }
            if(flg) {
                ret.append('-');
            }
            ret.reverse();
            System.out.println(ret);
        }
    }
}
